<template>
  <section class="personal-info">
    <group>
      <cell title="ID" :value="info.id"></cell>
      <cell :title="$t('nickname')" is-link :value="info.nickname" :link="{path: '/editnickname', query:{info: info.nickname}}"></cell>
      <cell :title="$t('phone num')" is-link :value="info.mobile" :link="{path: '/editphone', query:{info: info.mobile}}"></cell>
    </group>
    <group class="second">
      <cell :title="$t('edit pay pwd')" is-link value="" link="/edittradepwd"></cell>
      <cell :title="$t('edit pwd')" is-link value="" link="/editpwd"></cell>
      <!--<cell :title="$t('validate')" is-link :value="autherInfo" link="/validatefir"></cell>-->
      <cell :title="$t('wechart')" is-link :value="wechart" :link="{path: '/editWechat', query:{info: wechart}}"></cell>
      <cell :title="$t('alipay')" is-link :value="alipay" :link="{path: '/editAlipay', query:{info: alipay}}"></cell>
      <cell :title="$t('bankcard')" is-link :value="card" :link="{path: '/editCard', query:{num: card, realname: realname,bankname: bankname}}"></cell>
    </group>
  </section>
</template>

<i18n>
  eidt:
    en: edit
    zh-CN: 修改
  nickname:
    en: Nickname
    zh-CN: 昵称
  phone num:
    en: Phone Number
    zh-CN: 手机号
  edit pay pwd:
    en: Pay Password
    zh-CN: 交易密码
  edit pwd:
    en: Password
    zh-CN: 登陆密码
  validate:
    en: Validate
    zh-CN: 实名认证
  authenticate:
    en: authenticate
    zh-CN: 去认证
  unauthenticate:
    en: authenticate failed
    zh-CN: 认证失败
  authenticated already:
    en: Already
    zh-CN: 已认证
  under review:
    en: review
    zh-CN: 审核中
  wechart:
    en: weChart
    zh-CN: 微信
  alipay:
    en: aliPay
    zh-CN: 支付宝
  bankcard:
    en: Bank Card
    zh-CN: 银行卡
</i18n>

<script>
  import {Cell, Group} from 'vux'
  import {mapActions} from 'vuex'
  export default {
    name: 'PersonalInfo',
    components: {
      Cell,
      Group
    },
    data () {
      return {
        info: '',
        autherInfo: this.$t('authenticate'),
        tradePwd: '',
        wechart: '',
        alipay: '',
        card: '',
        bankname: '',
        realname: ''
      }
    },
    created () {
      this.init()
      // console.log(localStorage.token)
    },
    methods: {
      ...mapActions(['updateValitdate']),
      init () {
        let vue = this
        vue.post({
          url: '/api/account/get_index_info',
          params: {
            token: localStorage.token
          },
          success: function (data) {
            console.log(data)
            vue.info = data.data
            if (data.code === 1) {
              switch (data.data.is_certification) {
                case '1':
                  vue.autherInfo = vue.$t('under review')
                  break
                case '2':
                  vue.autherInfo = vue.$t('authenticated already')
                  break
                case '-1':
                  vue.autherInfo = vue.$t('unauthenticate')
                  break
                default:
                  vue.autherInfo = vue.$t('authenticate')
                  // vue.$router.push({path: '/validatefir'})
              }
              if (!data.data.pay_password) {
                vue.$router.push({path: '/edittradepwd'})
                vue.$store.dispatch('updateValitdate', {status: true})
              } else {
                vue.$store.dispatch('updateValitdate', {status: false})
              }
              if (!data.data.wechat) {
                vue.$router.push({path: '/editwechat'})
                vue.$store.dispatch('updateValitdate', {status: true})
              } else {
                vue.wechart = data.data.wechat
                vue.$store.dispatch('updateValitdate', {status: false})
              }
              if (!data.data.alipay) {
                vue.$router.push({path: '/editalipay'})
                vue.$store.dispatch('updateValitdate', {status: true})
              } else {
                vue.alipay = data.data.alipay
                vue.$store.dispatch('updateValitdate', {status: false})
              }
              if (!data.data.bank_card) {
                vue.$router.push({path: '/editCard'})
                vue.$store.dispatch('updateValitdate', {status: true})
              } else {
                vue.card = data.data.bank_card
                vue.bankname = data.data.bank_address
                vue.realname = data.data.bank_realname
                vue.$store.dispatch('updateValitdate', {status: false})
              }
            }
          }
        })
      }
    }
  }
</script>

<style lang="less" scoped>
  .personal-info {
    height: 100%;
    background-color: #fff;
  }
  div{
    font-size: 0.28rem;
    .second{
      border-top: 20px solid #fafafa;
      border-bottom: 0px;

    }
    .weui-cells:before{
      border-top: 0px solid red;
    }
    .weui-cell{
    }
  }
  .weui-cells:after{
    border: 0px solid #fafafa !important;
  }
  .weui-cells:before{
    border: 0px solid #fafafa !important;
  }
</style>
